package com.loto.webapp.action.ajax;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.loto.webapp.bo.manage.FeeFlowBo;
import com.loto.webapp.common.BaseAction;
import com.loto.webapp.model.FeeFlow;
import com.loto.webapp.model.response.Flows;

public class FlowDetailAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2952549477088696461L;
	private String un;
	private String st;
	private String et;

	private String msg;
	private List<Flows> flows;

	private FeeFlowBo feeFlowBo;

	public String execute() throws Exception {
		if (un == null || un.length() <= 0 || st == null || st.length() <= 0
				|| et == null || et.length() <= 0)
			this.setMsg("err");
		else {
			Date sDate, eDate = null;
			String pattern = "yyyy-MM-dd";
			SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);

			sDate = dateFormat.parse(st);
			eDate = dateFormat.parse(et);
			Calendar cal = GregorianCalendar.getInstance();
			cal.setTime(eDate);
			cal.add(Calendar.DATE, 1);
			eDate = cal.getTime();
			this.setMsg("suc");

			List<FeeFlow> feeFlowList = feeFlowBo.getDetail(sDate, eDate,
					Integer.valueOf(un));
			if (feeFlowList != null && feeFlowList.size() > 0) {
				flows = new ArrayList<Flows>();
				String datePattern = "yyyy-MM-dd HH:mm:ss";
				SimpleDateFormat dFormat = new SimpleDateFormat(datePattern);

				for (FeeFlow f : feeFlowList) {
					Flows ff = new Flows();
					ff.setFlowchange(new DecimalFormat("#0.00").format(f
							.getFeeFlowChanged()));
					ff.setFlowmemo(f.getFeeFlowMemo());
					ff.setFlowpayid(f.getFeeFlowPayNo());
					ff.setFlowtime(dFormat.format(f.getFeeFlowTime()));
					flows.add(ff);
				}
			} else {
				this.setMsg("err");
			}

		}
		return SUCCESS;
	}

	@JSON(serialize = false)
	public String getUn() {
		return un;
	}

	public void setUn(String un) {
		this.un = un;
	}

	@JSON(serialize = false)
	public String getSt() {
		return st;
	}

	public void setSt(String st) {
		this.st = st;
	}

	@JSON(serialize = false)
	public String getEt() {
		return et;
	}

	public void setEt(String et) {
		this.et = et;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public List<Flows> getFlows() {
		return flows;
	}

	public void setFlows(List<Flows> flows) {
		this.flows = flows;
	}

	@JSON(serialize = false)
	public FeeFlowBo getFeeFlowBo() {
		return feeFlowBo;
	}

	public void setFeeFlowBo(FeeFlowBo feeFlowBo) {
		this.feeFlowBo = feeFlowBo;
	}
}
